//
//  HeliosRoughSim.m
//  MacHeliosSim
//
//  Created by Paul Thompson on 8/12/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "HeliosRoughSim.h"


@implementation HeliosRoughSim
-(id)initWithReaction:(Reaction *)theReaction
{
//	theData = [[RoughSimReturnData alloc] init];
	myReaction = theReaction;
	return self;
}


-(RoughSimReturnData *)labEjectileDistanceForKinCalcData:(KinCalcReturnData *)theData
										AndFieldStrength:(double)theFieldStength
{
	double cSquared = 8.98755179e16;  //speed of light squared in m^2/s^2
	double massConverter = 931.494028; //MeV per c^2 per u
	double uToKG = 1.660538782e-27; // kg per u
	double coulombsPerQ = 1.602176487e-19;
	
	double mass = (myReaction.ejectileNuclide.nucleonCount*massConverter 
				   + myReaction.ejectileNuclide.deltaM/1000.0); // mass in MeV/c^2
	
	double massInKG = mass/massConverter*uToKG; // = mass in kg
#ifdef DEBUG
	NSLog(@"Ejectile mass in MeV: %g\tmass in KG: %g",mass,massInKG);
	NSLog(@"omega: %f",omega);
#endif
	double omega = myReaction.ejectileNuclide.protonCount*coulombsPerQ*theFieldStength/massInKG;
	double velocity = sqrt( 2.0*theData.energy*cSquared/mass);
	double vPerp = velocity*cos([theData labAngle]);
	
	double distance = velocity*cos([theData labAngle])/omega*100.0*2*pi;
	
	RoughSimReturnData *temp = [[RoughSimReturnData alloc] initWithKinData:theData];
	
	temp.vPerp = vPerp;
	temp.velocity = velocity;
	temp.distanceTraveled = distance;
	temp.cyclotronFrequency = omega;
	temp.fieldStrength = theFieldStength;
	
	return temp;
	
	
	
	
	
	
	
	return nil;
}
-(RoughSimReturnData *)labProductDistanceForKinCalcData:(KinCalcReturnData *)theData
									   AndFieldStrength:(double)theFieldStength
{
	double cSquared = 8.98755179e16;  //speed of light squared in m^2/s^2
	double massConverter = 931.494028;
	double uToKG = 1.660538782e-27; // kg per u
	double coulombsPerQ = 1.602176487e-19;

	double mass = (myReaction.productNuclide.nucleonCount*massConverter 
				   + myReaction.productNuclide.deltaM/1000.0);
	
	double massInKG = mass/massConverter*uToKG; // = mass in kg
	
	double omega = myReaction.productNuclide.protonCount*coulombsPerQ*theFieldStength/massInKG;
	
	double velocity = sqrt( 2.0*theData.energy*cSquared/mass);
	double vPerp = velocity*cos([theData labAngle]);
	
	//double distance = velocity/omega*100.0;
	double distance = velocity*cos([theData labAngle])/omega*100.0*2*pi;

	RoughSimReturnData *temp = [[RoughSimReturnData alloc] initWithKinData:theData];
	
	temp.velocity = velocity;
	temp.vPerp = vPerp;
	temp.distanceTraveled = distance;
	temp.cyclotronFrequency = omega;
	temp.fieldStrength = theFieldStength;
	
	return temp;
	
}

@end
